package shortlink.remote;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import shortlink.common.convention.result.Result;
import shortlink.config.OpenFeignConfiguration;
import shortlink.remote.dto.req.*;
import shortlink.remote.dto.resp.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@FeignClient(value = "short-link-project",
//        url = "${http://127.0.0.1:${server.port}}",
        configuration = OpenFeignConfiguration.class)
public interface ShortLinkRemoteService { 
//    创建短链接
    @PostMapping("/api/short-link/project/link/create")
    Result<ShortLinkCreateRespDTO> createShortLink( @RequestBody ShortLinkCreateReqDTO requestParam);
//   default Result<ShortLinkCreateRespDTO> createShortLink(ShortLinkCreateReqDTO requestParam){
//       String resultBodystr = HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/create", JSON.toJSONString(requestParam));
//       return JSON.parseObject(resultBodystr,new TypeReference<>(){});
//    }

//批量创建短链接
    @PostMapping("/api/short-link/project/link/Batchcreate")
    Result<ShortLinkBatchCreateRespDTO> batchCreateShortLink(@RequestBody ShortLinkBatchCreateReqDTO requestParam);
//   default Result<ShortLinkBatchCreateRespDTO> batchCreateShortLink(ShortLinkBatchCreateReqDTO requestParam){
//       String resultBodystr = HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/Batchcreate", JSON.toJSONString(requestParam));
//       return JSON.parseObject(resultBodystr,new TypeReference<>(){});
//   }
//分页查询短链接
    @GetMapping("/api/short-link/project/link/pageselect")
    Result<Page<ShortLinkPageRespDTO>> pageShortLink(@RequestParam("gid") String gid,
                                                      @RequestParam("orderTag") String orderTag,
                                                      @RequestParam("current") Long current,
                                                      @RequestParam("size") Long size);
//  default   Result<IPage<ShortLinkPageRespDTO>> pageShortLink(ShortLinkPageReqDTO requestParam){
//      Map<String, Object> requestMap=new HashMap<>();
//      requestMap.put("gid",requestParam.getGid());
//      requestMap.put("current",requestParam.getCurrent());
//      requestMap.put("size",requestParam.getSize());
//      String resultPagestr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/admin/link/pageselect", requestMap);
//      return JSON.parseObject(resultPagestr,new TypeReference<>(){});
//  }
//修改短链接
    @PostMapping("/api/short-link/project/link/update")
    void updateShortLink(@RequestBody ShortLinkUpdateReqDTO requestParam);
//   default void updateShortLink(ShortLinkUpdateReqDTO requestParam){
//       HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/update", JSON.toJSONString(requestParam));
//   }
//查询的分组内短链接数量
    @GetMapping("/api/short-link/project/link/groupselect")
    Result<List<ShortLinkGroupCountQueryRespDTO>> listGroupShortLinkCount(@RequestParam("requestParam") List<String> requestParam);
//   default Result<List<ShortLinkGroupCountQueryRespDTO>> listGroupShortLinkCount(List<String> requestParam){
//       Map<String, Object> requestMap=new HashMap<>();
//       requestMap.put("requestParam",requestParam);
//       String resultstr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/link/groupselect", requestMap);
//       return JSON.parseObject(resultstr,new TypeReference<>(){});
//   }
//保存至回收站
    @PostMapping("/api/short-link/project/link/SaveRecycleBin")
     void saveRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam);
//   default void saveRecycleBin(RecycleBinSaveReqDTO requestParam){
//       HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/SaveRecycleBin",JSON.toJSONString(requestParam));
//   }
//恢复短链接
    @PostMapping("/api/short-link/project/link/RecoverRecycleBin")
    void recoverRecycleBin(@RequestBody RecycleBinRecoverReqDTO requestParam);
//   default void recoverRecycleBin(RecycleBinRecoverReqDTO requestParam){
//       HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/RecoverRecycleBin",JSON.toJSONString(requestParam));
//   }
//移除短链接
    @PostMapping("/api/short-link/project/link/RemoveRecycleBin")
    void removeRecycleBin(RecycleBinRemoveReqDTO requestParam);
//   default void removeRecycleBin(RecycleBinRemoveReqDTO requestParam){
//       HttpUtil.post("http://127.0.0.1:8001/api/short-link/project/link/RemoveRecycleBin",JSON.toJSONString(requestParam));
//   }
//分页查询短链接
    @GetMapping("/api/short-link/project/link/PageRecycleBin")
    Result<IPage<ShortLinkPageRespDTO>> pageRecycleBinShortLink(@RequestParam("gidList") List<String> gidList,
                                                                @RequestParam("current") Long current,
                                                                @RequestParam("size") Long size);
//   default Result<IPage<ShortLinkPageRespDTO>> pageRecycleBinShortLink(ShortLinkRecycleBinPageReqDTO requestParam){
//       Map<String, Object> requestMap=new HashMap<>();
//       requestMap.put("gidList",requestParam.getGidList());
//       requestMap.put("current",requestParam.getCurrent());
//       requestMap.put("size",requestParam.getSize());
//       String resultPagestr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/link/PageRecycleBin", requestMap);
//       return JSON.parseObject(resultPagestr,new TypeReference<>(){});
//   }

//根据短链接获取指定之间内的监控数据
    @GetMapping("/api/short-link/project/linkstats/stats")
    Result<ShortLinkStatsRespDTO> oneShortLinkStats(@RequestParam("fullShortUrl") String fullShortUrl,
                                                    @RequestParam("gid") String gid,
                                                    @RequestParam("enableStatus") Integer enableStatus,
                                                    @RequestParam("startDate") String startDate,
                                                    @RequestParam("endDate") String endDate);
//   default Result<ShortLinkStatsRespDTO> oneShortLinkStats(ShortLinkStatsReqDTO requestParam){
//       String ResultBodystr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/linkstats/stats", BeanUtil.beanToMap(requestParam));
//       return JSON.parseObject(ResultBodystr,new TypeReference<>(){});
//   }
//根据短链接f分组获取指定之间内的监控数据
    @GetMapping("/api/short-link/project/linkstats/groupstats")
    Result<ShortLinkStatsRespDTO> groupShortLinkStats(@RequestParam("gid") String gid,
                                                      @RequestParam("startDate") String startDate,
                                                      @RequestParam("endDate") String endDate);
//   default Result<ShortLinkStatsRespDTO> groupShortLinkStats(ShortLinkGroupStatsReqDTO requestParam){
//       String ResultBodystr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/linkstats/groupstats", BeanUtil.beanToMap(requestParam));
//       return JSON.parseObject(ResultBodystr,new TypeReference<>(){});
//   }
//访问单个短链接指定时间内访问记录监控数据
    @GetMapping("/api/short-link/project/linkstats/statslogs")
    Result<Page<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(@RequestParam("fullShortUrl") String fullShortUrl,
                                                                               @RequestParam("gid") String gid,
                                                                               @RequestParam("startDate") String startDate,
                                                                               @RequestParam("endDate") String endDate,
                                                                               @RequestParam("enableStatus") Integer enableStatus,
                                                                               @RequestParam("current") Long current,
                                                                               @RequestParam("size") Long size);
//   default Result<Page<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO requestParam){
//       Map<String, Object> requestMap = BeanUtil.beanToMap(requestParam);
//       String ResultBodystr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/linkstats/statslogs", requestMap);
//       return JSON.parseObject(ResultBodystr,new TypeReference<>(){});
//   }
//访问分组短链接指定时间内访问记录监控数据
    @GetMapping("/api/short-link/project/linkstats/groupstatslogs")
    Result<Page<ShortLinkStatsAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(@RequestParam("gid") String gid,
                                                                                    @RequestParam("startDate") String startDate,
                                                                                    @RequestParam("endDate") String endDate,
                                                                                    @RequestParam("current") Long current,
                                                                                    @RequestParam("size") Long size);
//   default Result<Page<ShortLinkStatsAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(ShortLinkGroupStatsAccessRecordReqDTO requestParam){
//       Map<String, Object> requestMap = BeanUtil.beanToMap(requestParam);
//       String ResultBodystr = HttpUtil.get("http://127.0.0.1:8001/api/short-link/project/linkstats/groupstatslogs", requestMap);
//       return JSON.parseObject(ResultBodystr,new TypeReference<>(){});
//   }
}
